/*
 * All rights Reserved, Designed By DataDriver
 * Copyright:    DataDriver.Inc
 * Company:      Zhuo Wo Infomation Technology (ShangHai) CO.LTD
 */
package com.sun.dubboconsumer.config;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.sun.service.UserService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 除了xml文件和properties文件的方式外
 * 还可以通过API编码的方式实现
 */

//@Configuration
public class DubboConfig {

    /**
     * 当前应用的配置
     *
     * @return
     */
    @Bean
    public ApplicationConfig applicationConfig() {
        ApplicationConfig config = new ApplicationConfig();
        config.setName("dubbo-server-consumer");
        return config;
    }


    /**
     * 注册中心的相关配置
     *
     * @return
     */
    @Bean
    public RegistryConfig registryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress("150.158.163.91:2181");
        return registryConfig;
    }

    /**
     * 服务提供者的相关配置
     *
     * @return
     */
    @Bean
    public ProtocolConfig protocolConfig() {
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(20880);
        return protocolConfig;
    }


    /**
     * 服务提供者暴露服务配置
     *
     * @return
     */

    @Bean
    public ServiceConfig<UserService> serviceServerConfig() {
        ServiceConfig<UserService> serverConfig = new ServiceConfig<UserService>();
        serverConfig.setInterface(UserService.class);
        serverConfig.setVersion("1.0.0");
        // 暴露及注册服务
        serverConfig.export();
        return serverConfig;
    }
}
